<template>
  <div>
    <h2>周销图</h2>
    <div class="chart" id="myecharts">图表容器2</div>
  </div>
</template>

<script>
import { inject, onMounted, reactive } from "vue";
export default {
  setup() {
    let $echarts = inject("echarts");
    let $http = inject("axios");

    let data = reactive({});

    async function getState() {
      data = await $http({ url: "/two/data" });
    }
    onMounted(() => {
      getState().then(() => {
        // console.log(data);
        let myChart = $echarts.init(document.getElementById("myecharts"));
        myChart.setOption({
          tooltip:{
            trigger:"axis",
            axisPoniter:{
              type:"cross",
              label:{
                backgroundColor:"#e6b60"
              }
            }
          },
          legend:{
            data:["服饰","数码","家电","家具","日化"]
          },
          grid:{
            left:"1%",
            containLabel:true
          },
          xAxis: {
            type: "category",
            data: data.data.chartData.chartData.day,
            boundaryGap: false, //清除间隙
            axisLine:{
              lineStyle:{
                color:"#fff"
              }
            }
          },
          yAxis: {
            type: "value",
            axisLine:{
              lineStyle:{
                color:"#fff"
              }
            }
          },
          series: [
            {
              name: "服饰",
              type: "line",
              data: data.data.chartData.chartData.num.Chemicals,
              smoth: true, //曲线图效果
              showSymbol: false, //隐藏所有数据点
              stack: "Total", //数据堆叠
              lineStyle: {
                width: 0,
              },
              emphasis: {
                focus: "series",
              },
              areaStyle: {
                opacity: 0.8,
                color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgb(128,255,165)",
                  },
                  {
                    offset: 1,
                    color: "rgb(1,191,236)",
                  },
                ]),
              },
            },
            {
              name: "数码",
              type: "line",
              data: data.data.chartData.chartData.num.Clothes,
              smoth: true, //曲线图效果
              showSymbol: false, //隐藏所有数据点
              stack: "Total", //数据堆叠
              lineStyle: {
                width: 0,
              },
              emphasis: {
                focus: "series",
              },
              areaStyle: {
                opacity: 0.8,
                color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgb(0,121,255)",
                  },
                  {
                    offset: 1,
                    color: "rgb(77,119,255)",
                  },
                ]),
              },
            },
            {
              name: "家电",
              type: "line",
              data: data.data.chartData.chartData.num.Eletrical,
              smoth: true, //曲线图效果
              showSymbol: false, //隐藏所有数据点
              stack: "Total", //数据堆叠
              lineStyle: {
                width: 0,
              },
              emphasis: {
                focus: "series",
              },
              areaStyle: {
                opacity: 0.8,
                color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgb(55,162,255)",
                  },
                  {
                    offset: 1,
                    color: "rgb(116,21,219)",
                  },
                ]),
              },
            },
            {
              name: "家具",
              type: "line",
              data: data.data.chartData.chartData.num.digit,
              smoth: true, //曲线图效果
              showSymbol: false, //隐藏所有数据点
              stack: "Total", //数据堆叠
              lineStyle: {
                width: 0,
              },
              emphasis: {
                focus: "series",
              },
              areaStyle: {
                opacity: 0.8,
                color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgb(255,0,135)",
                  },
                  {
                    offset: 1,
                    color: "rgb(135,0,157)",
                  },
                ]),
              },
            },
            {
              name: "日化",
              type: "line",
              data: data.data.chartData.chartData.num.gear,
              smoth: true, //曲线图效果
              showSymbol: false, //隐藏所有数据点
              stack: "Total", //数据堆叠
              lineStyle: {
                width: 0,
              },
              emphasis: {
                focus: "series",
              },
              areaStyle: {
                opacity: 0.8,
                color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "rgb(255,191,0)",
                  },
                  {
                    offset: 1,
                    color: "rgb(224,62,76)",
                  },
                ]),
              },
            },
          ],
        });
      });
    });
    return {
      getState,
      data,
    };
  },
};
</script>

<style>
.chart {
  height: 400px;
  width: 400px;
}
</style>
